<?php 
$sql =	"SELECT
			  c.page_id,
			  d.title,
			  d.description,
			  d.meta_key,
			  d.meta_description	
		  FROM
			  pages AS c,
			  page_description AS d
		  WHERE
		  
			  c.page_id = d.page_id
			  AND
			  d.lang_id = '".$_SESSION['lang_id']."'
			  AND
			  c.sef_url = '".$sef_url."' 
			  AND c.published
		  ";
$result = query($sql);
$row = mysql_fetch_object($result);


head(sth($row->title),sth($row->meta_description));



?>


		<div id="content">
			
			<div class="left full">
				<h1><?=stripslashes($row->title)?></h1>
				 
				<?=stripslashes($row->description)?>
                 
				<div id="city-opt" class="options">
				  <a href="#">Choose City</a>
				  
				</div>
				
				<div id="park-opt" class="options" style="display:none;" >
				  <a href="#">Choose Location</a>
				  
				</div>
				
				
				<table class="tariffs" width="100%">
					<tr>
						<td>Zone</td>
						<td>15 min</td>
						<td>30 min</td>
						<td>1 hour</td>
						<td>2 hours</td>
						<td>3 hours</td>
						<td>4 hours</td>
					</tr>
					
					
				</table>

                 
			</div>
            <div id="sex">
            </div>
			
		</div>
		<script type="application/javascript">
		var _round = Math.round;
		Math.round = function(number, decimals)
		{
		  if (arguments.length == 1)
			return _round(number);
		
		  var multiplier = Math.pow(10, decimals);
		  
		  var toStr = String(_round(number * multiplier) / multiplier);
		  var arr = toStr.split(".");
		  
		  if(arr[1])
		  {
			if(String(arr[1]).length == 1)
			{
				 toStr += '0';
			}
			  
		  }else{
			  toStr += '.00';
		  }

		  return toStr;
		}
		
		function print_r(o){
			return JSON.stringify(o,null,'\t').replace(/\n/g,'<br>').replace(/\t/g,'&nbsp;&nbsp;&nbsp;'); }
		
		$(document).ready(function() {
        
		var appname;
		var json;
		 $.ajax({
					type: 'GET',
					url: 'https://portal.olapark.pt/OlaParkUsersDataService.svc/GetAllParkSystems?<?=date('Y-m-d-g-i')?>',
					data: '',
					async: false,
					success: function(msg){
						
						json = JSON.parse(msg.GetAllParkSystemsResult);
						
						
						
					},
					error: function(msg){
						alert('Err:'+ msg)
					}
				});
		
		//Зарежда градовете		
			function loadcities(){
				
				$.each(json, function(index, value) {
					var tr = true;	
					$('#city-opt a').each(function() {
                        
						if($(this).text() == value['City'])
						{
							tr = false;	
						}
					});
						if(tr)
						{
							$('#city-opt').append('<a href="#">'+value['City']+'</a>');
						}
					});
					
					
			}
		loadcities();
		//City clik function	
		$('#city-opt a').click(function(e){
				e.preventDefault();
				var value = $(this).text();	
				var option = $(this).attr('href');
				$(this).parent().find('a:first').text(value);
				$(this).parent().find('a:first').attr('href', option);
				
				
				loadpark($(this).text());
				});
				
			
			
			function loadpark(city)
			{
				$('#park-opt').html('<a href="#">Choose Location</a>');
				$.each(json, function(index, value) {
						
					    
						if(city == value['City'])
						{
							$('#park-opt').append('<a  href="#">'+value['AppName']+'</a>');
							
							$('#park-opt').show();
							
							
							$('#park-opt a').click(function(e){
							e.preventDefault();
							
							var value = $(this).text();	
							var option = $(this).attr('href');
							$(this).parent().find('a:first').text(value);
							$(this).parent().find('a:first').attr('href', option);
							
							appname = $(this).text();
							//alert('zsfgadfg');
							loadtarif();
					});	
							
							
						}
						
						});
						
						
					
			}
			
			function loadtarif()
			{
								$('.tariffs').html('<tr>\n\n<td>Zone</td>\n<td>15 min</td>\n<td>30 min</td>\n<td>1 hour</td>\n<td>2 hours</td>\n<td>3 hours</td>\n<td>4 hours</td>\n\n</tr>\n');
				
				$.each(json, function(index, value) {
						
					    
						if(appname == value['AppName'])
						{
							
							//$('#sex').html(print_r(value['Zones']));
							//$('#park-opt').append('<a data-title="loadtarif(\"'+value['AppName']+'\")" href="#'+value['AppName']+'">'+value['AppName']+'</a>');
							
							$.each(value['Zones'], function(index, val) {
								var calprice = val['MinPrice']/val['MinParkTime'];
								var tr = '<tr class="red" >';
									tr +='<td style="background-color:'+val['ZoneColor']+'">'+val['ZoneName']+'</td>';							
									tr +='<td style="background-color:'+val['ZoneColor']+'">'+Math.round(15*calprice,2)+' '+value['currSymbol']+'</td>';
		if(val['MaxParkTime']>=  30)tr +='<td style="background-color:'+val['ZoneColor']+'">'+Math.round(30*calprice,2)+' '+value['currSymbol']+'</td>';
		if(val['MaxParkTime']>=  60)tr +='<td style="background-color:'+val['ZoneColor']+'">'+Math.round(60*calprice,2)+' '+value['currSymbol']+'</td>';
	    if(val['MaxParkTime']>= 120)tr +='<td style="background-color:'+val['ZoneColor']+'">'+Math.round(120*calprice,2)+' '+value['currSymbol']+'</td>';
		if(val['MaxParkTime']>= 180)tr +='<td style="background-color:'+val['ZoneColor']+'">'+Math.round(180*calprice,2)+' '+value['currSymbol']+'</td>';
		if(val['MaxParkTime']>= 240)tr +='<td style="background-color:'+val['ZoneColor']+'">'+Math.round(240*calprice,2)+' '+value['currSymbol']+'</td>';
								tr +='</tr>';	
									
								$('.tariffs').append(tr);
								});	
						}
						
						
						
						});
				
				
			}
			
			
			
				
						
						
		});				
		</script>
   
	
<?php

foot();
?>